function BxInterfaceGrid(e){this.oActions={};this.oColsMeta={};this.oColsNames={};this.customNames={};this.oEditData={};this.oSaveData={};this.oOptions={};this.oVisibleCols=null;this.vars={};this.menu=null;this.settingsMenu=[];this.filterMenu=[];this.checkBoxCount=0;this.bColsChanged=false;this.bViewsChanged=false;this.oFilterRows={};this.activeRow=null;var t=this;this.table_id=e;this.InitTable=function(){var e=document.getElementById(this.table_id);if(!e||e.rows.length<1||e.rows[0].cells.length<1)return;var i;var s=e.rows[0].cells.length;for(i=0;i<s;i++){var a;for(a=0;a<2;a++){var n=e.rows[a].cells[i];n.onmouseover=function(){t.HighlightGutter(this,true)};n.onmouseout=function(){t.HighlightGutter(this,false)};if(a==1){if(n.className&&(n.className=="bx-actions-col"||n.className=="bx-checkbox-col"))continue;if(this.vars.user_authorized){n.onbxdragstart=t.DragStart;n.onbxdragstop=t.DragStop;n.onbxdrag=t.Drag;n.onbxdraghout=function(){t.HighlightGutter(this,false)};jsDD.registerObject(n);n.onbxdestdraghover=t.DragHover;n.onbxdestdraghout=t.DragOut;n.onbxdestdragfinish=t.DragFinish;jsDD.registerDest(n)}}}}var l=e.rows.length;for(i=0;i<l;i++){var r=e.rows[i];if(r.className&&r.className=="bx-grid-footer")continue;r.cells[0].className+=" bx-left";r.cells[r.cells.length-1].className+=" bx-right";if(i>=2){var o=r.cells[0].childNodes[0];if(o&&o.tagName&&o.tagName.toUpperCase()=="INPUT"&&o.type.toUpperCase()=="CHECKBOX"){o.onclick=function(){t.SelectRow(this);t.EnableActions()};jsUtils.addEvent(r,"click",t.OnClickRow);this.checkBoxCount++}r.onmouseover=function(){t.HighlightRow(this,true)};r.onmouseout=function(){t.HighlightRow(this,false)};if(i%2==0)r.className+=" bx-odd";else r.className+=" bx-even"}if(r.oncontextmenu)jsUtils.addEvent(r,"contextmenu",this.OnRowContext)}if(e.rows.length>2){e.rows[2].className+=" bx-top";var c=e.rows[e.rows.length-1];if(c.className&&c.className=="bx-grid-footer")c=e.rows[e.rows.length-2];c.className+=" bx-bottom"}};this.OnRowContext=function(e){if(!t.menu)return;if(!e)e=window.event;if(!phpVars.opt_context_ctrl&&e.ctrlKey||phpVars.opt_context_ctrl&&!e.ctrlKey)return;var i;if(e.target)i=e.target;else if(e.srcElement)i=e.srcElement;var s=i;while(s&&!(s.tagName&&s.tagName.toUpperCase()=="TD"&&s.oncontextmenu))s=jsUtils.FindParentObject(s,"td");var a=null;if(s&&s.oncontextmenu){a=s.oncontextmenu();a[a.length]={SEPARATOR:true}}s=i;while(s&&!(s.tagName&&s.tagName.toUpperCase()=="TR"&&s.oncontextmenu))s=jsUtils.FindParentObject(s,"tr");var n=t.menu;n.PopupHide();t.activeRow=s;if(t.activeRow&&!BX.hasClass(s,"bx-grid-gutter")&&!BX.hasClass(s,"bx-grid-head"))t.activeRow.className+=" bx-active";n.OnClose=function(){if(t.activeRow){t.activeRow.className=t.activeRow.className.replace(/\s*bx-active/i,"");t.activeRow=null}t.SaveColumns()};var l=BX.util.array_merge(a,s.oncontextmenu());if(l.length==0)return;n.SetItems(l);n.BuildItems();var r=jsUtils.GetWindowScrollPos();var o=e.clientX+r.scrollLeft;var c=e.clientY+r.scrollTop;var d={};d["left"]=d["right"]=o;d["top"]=d["bottom"]=c;n.PopupShow(d);e.returnValue=false;if(e.preventDefault)e.preventDefault()};this.ShowActionMenu=function(e,i){t.menu.PopupHide();t.activeRow=jsUtils.FindParentObject(e,"tr");if(t.activeRow)t.activeRow.className+=" bx-active";t.menu.ShowMenu(e,t.oActions[i],false,false,function(){if(t.activeRow){t.activeRow.className=t.activeRow.className.replace(/\s*bx-active/i,"");t.activeRow=null}})};this.HighlightGutter=function(e,t){var i=e.parentNode.parentNode.parentNode;var s=i.rows[0].cells[e.cellIndex];var a=s.className.indexOf("bx-sorted")!=-1;if(t){if(a){s.className+=" bx-over-sorted";e.className+=" bx-over-sorted"}else{s.className+=" bx-over";e.className+=" bx-over"}}else{if(a){s.className=s.className.replace(/\s*bx-over-sorted/i,"");e.className=e.className.replace(/\s*bx-over-sorted/i,"")}else{s.className=s.className.replace(/\s*bx-over/i,"");e.className=e.className.replace(/\s*bx-over/i,"")}}};this.HighlightRow=function(e,t){if(t)e.className+=" bx-over";else e.className=e.className.replace(/\s*bx-over/i,"")};this.SelectRow=function(e){var t=e.parentNode.parentNode;var i=t.parentNode.parentNode;var s=document.getElementById(i.id+"_selected_span");var a=parseInt(s.innerHTML);if(e.checked){t.className+=" bx-selected";a++}else{t.className=t.className.replace(/\s*bx-selected/gi,"");a--}s.innerHTML=a.toString();var n=document.getElementById(i.id+"_check_all");if(a==this.checkBoxCount)n.checked=true;else n.checked=false};this.OnClickRow=function(e){if(!e)e=window.event;if(!e.ctrlKey)return;var i=e.target?e.target:e.srcElement?e.srcElement:null;if(!i)return;if(!i.parentNode.cells)return;var s=i.parentNode.cells[0].childNodes[0];if(s&&s.tagName&&s.tagName.toUpperCase()=="INPUT"&&s.type.toUpperCase()=="CHECKBOX"&&!s.disabled){s.checked=!s.checked;t.SelectRow(s)}t.EnableActions()};this.SelectAllRows=function(e){var t=document.getElementById(this.table_id);var i=e.checked;var s;var a=t.rows.length;for(s=2;s<a;s++){var n=t.rows[s].cells[0].childNodes[0];if(n&&n.tagName&&n.tagName.toUpperCase()=="INPUT"&&n.type.toUpperCase()=="CHECKBOX"){if(n.checked!=i&&!n.disabled){n.checked=i;this.SelectRow(n)}}}this.EnableActions()};this.EnableActions=function(){var e=document.forms["form_"+this.table_id];if(!e)return;var t=this.IsActionEnabled();var i=this.IsActionEnabled("edit");if(e.apply)e.apply.disabled=!t;var s=document.getElementById("edit_button_"+this.table_id);if(s)s.className="context-button icon action-edit-button"+(i?"":"-dis");s=document.getElementById("delete_button_"+this.table_id);if(s)s.className="context-button icon action-delete-button"+(t?"":"-dis")};this.IsActionEnabled=function(e){var t=document.forms["form_"+this.table_id];if(!t)return;var i=false;var s=document.getElementById(this.table_id+"_selected_span");if(s&&parseInt(s.innerHTML)>0)i=true;var a=t["action_all_rows_"+this.table_id];if(e=="edit")return!(a&&a.checked)&&i;else return a&&a.checked||i};this.SwitchActionButtons=function(e){var t=document.getElementById("bx_grid_"+this.table_id+"_action_buttons");var i=t;while(i=jsUtils.FindNextSibling(i,"td"))i.style.display=e?"none":"";t.style.display=e?"":"none"};this.ActionEdit=function(e){if(this.IsActionEnabled("edit")){var t=document.forms["form_"+this.table_id];if(!t)return;this.SwitchActionButtons(true);var i=t["ID[]"];if(!i.length)i=new Array(i);for(var s=0;s<i.length;s++){var a=i[s];if(a.checked){var n=jsUtils.FindParentObject(a,"tr");BX.denyEvent(n,"dblclick");var l=jsUtils.FindParentObject(a,"td");l=jsUtils.FindNextSibling(l,"td");if(l.className=="bx-actions-col")l=jsUtils.FindNextSibling(l,"td");var r=a.value;this.oSaveData[r]={};for(var o in this.oColsMeta){if(this.oColsMeta[o].editable==true&&this.oEditData[r][o]!==false){this.oSaveData[r][o]=l.innerHTML;l.innerHTML="";var c=this.oEditData[r][o];var d="FIELDS["+r+"]["+o+"]";switch(this.oColsMeta[o].type){case"checkbox":l.appendChild(BX.create("INPUT",{props:{type:"hidden",name:d,value:"N"}}));l.appendChild(BX.create("INPUT",{props:{type:"checkbox",name:d,value:"Y",checked:c=="Y",defaultChecked:c=="Y"}}));break;case"list":var h=[];for(var f in this.oColsMeta[o].items){h[h.length]=BX.create("OPTION",{props:{value:f,selected:f==c},text:this.oColsMeta[o].items[f]})}l.appendChild(BX.create("SELECT",{props:{name:d},children:h}));break;case"date":var v=BX.create("SPAN",{style:{whiteSpace:"nowrap"}});v.appendChild(BX.create("INPUT",{props:{type:"text",name:d,value:c,size:this.oColsMeta[o].size?this.oColsMeta[o].size:10}}));v.appendChild(BX.create("A",{props:{href:"javascript:void(0);",title:this.vars.mess.calend_title},html:'<img src="'+this.vars.calendar_image+'" alt="'+this.vars.mess.calend_title+'" class="calendar-icon" onclick="BX.calendar({node:this, field:\''+d+"', bTime: true, currentTime: '"+this.vars.server_time+'\'});" onmouseover="this.className+=\' calendar-icon-hover\';" onmouseout="this.className = this.className.replace(/s*calendar-icon-hover/ig, \'\');" border="0"/>'}));l.appendChild(v);break;default:var u={type:"text",name:d,value:c,size:this.oColsMeta[o].size?this.oColsMeta[o].size:15};if(this.oColsMeta[o].maxlength)u.maxLength=this.oColsMeta[o].maxlength;l.appendChild(BX.create("INPUT",{props:u}));break}}l=jsUtils.FindNextSibling(l,"td")}}a.disabled=true}t.elements["action_button_"+this.table_id].value="edit"}};this.ActionCancel=function(){var e=document.forms["form_"+this.table_id];if(!e)return;this.SwitchActionButtons(false);var t=e["ID[]"];if(!t.length)t=new Array(t);for(var i=0;i<t.length;i++){var s=t[i];if(s.checked){var a=jsUtils.FindParentObject(s,"tr");BX.allowEvent(a,"dblclick");var n=jsUtils.FindParentObject(s,"td");n=jsUtils.FindNextSibling(n,"td");if(n.className=="bx-actions-col")n=jsUtils.FindNextSibling(n,"td");var l=s.value;for(var r in this.oColsMeta){if(this.oColsMeta[r].editable==true&&this.oEditData[l][r]!==false)n.innerHTML=this.oSaveData[l][r];n=jsUtils.FindNextSibling(n,"td")}}s.disabled=false}e.elements["action_button_"+this.table_id].value=""};this.ActionDelete=function(){var e=document.forms["form_"+this.table_id];if(!e)return;e.elements["action_button_"+this.table_id].value="delete";BX.submit(e)};this.DeleteItem=function(e,t){var i=document.getElementById("ID_"+e);if(i){if(confirm(t)){var s=document.forms["form_"+this.table_id];if(!s)return;var a=s["ID[]"];if(!a.length)a=new Array(a);for(var n=0;n<a.length;n++){a[n].checked=false}i.checked=true;this.ActionDelete()}}};this.ForAllClick=function(e){if(e.checked&&!confirm(this.vars.mess.for_all_confirm)){e.checked=false;return}var t=e.form["ID[]"];if(t){if(!t.length)t=new Array(t);for(var i=0;i<t.length;i++)t[i].disabled=e.checked}this.EnableActions()};this.Sort=function(e,i,s,a,n){var l;if(s==""){var r=null,o=false;if(n.length>0)r=n[0];if(!r)r=window.event;if(r)o=r.ctrlKey;l=o?a=="asc"?"desc":"asc":a}else if(s=="asc")l="desc";else l="asc";e+=l;BX.ajax.get("/bitrix/components"+t.vars.component_path+"/settings.php?GRID_ID="+t.table_id+"&action=savesort&by="+i+"&order="+l+"&sessid="+t.vars.sessid,function(){t.Reload(e)})};this.InitVisCols=function(){if(this.oVisibleCols==null){this.oVisibleCols={};for(var e in this.oColsMeta)this.oVisibleCols[e]=true}};this.CheckColumn=function(e,t){var i=this.menu.GetMenuByItemId(t.id);var s=!(i.GetItemInfo(t).ICON=="checked");i.SetItemIcon(t,s?"checked":"");this.InitVisCols();this.oVisibleCols[e]=s;this.bColsChanged=true};this.HideColumn=function(e){this.InitVisCols();this.oVisibleCols[e]=false;this.bColsChanged=true;this.SaveColumns()};this.ApplySaveColumns=function(){this.menu.PopupHide();this.SaveColumns()};this.SaveColumns=function(e){var i="";if(e){i=e}else{if(!t.bColsChanged)return;for(var s in t.oVisibleCols)if(t.oVisibleCols[s])i+=(i!=""?",":"")+s}BX.ajax.get("/bitrix/components"+t.vars.component_path+"/settings.php?GRID_ID="+t.table_id+"&action=showcolumns&columns="+i+"&sessid="+t.vars.sessid,function(){t.Reload()})};this.Reload=function(e){jsDD.Disable();if(!e){e=this.vars.current_url}if(this.vars.ajax.AJAX_ID!=""){BX.ajax.insertToNode(e+(e.indexOf("?")==-1?"?":"&")+"bxajaxid="+this.vars.ajax.AJAX_ID,"comp_"+this.vars.ajax.AJAX_ID)}else{window.location=e}};this.SetTheme=function(e,i){BX.loadCSS(this.vars.template_path+"/themes/"+i+"/style.css");BX(t.table_id).className="bx-interface-grid bx-interface-grid-theme-"+i;var s=this.menu.GetMenuByItemId(e.id);s.SetAllItemsIcon("");s.SetItemIcon(e,"checked");BX.ajax.get("/bitrix/components"+t.vars.component_path+"/settings.php?GRID_ID="+t.table_id+"&action=settheme&theme="+i+"&sessid="+t.vars.sessid)};this.SetView=function(e){var i=t.oOptions.views[e].saved_filter;var s=i&&t.oOptions.filters[i]?function(){t.ApplyFilter(i)}:function(){t.Reload()};BX.ajax.get("/bitrix/components"+t.vars.component_path+"/settings.php?GRID_ID="+t.table_id+"&action=setview&view_id="+e+"&sessid="+t.vars.sessid,s)};this.EditCurrentView=function(){this.ShowSettings(this.oOptions.views[this.oOptions.current_view],function(){t.SaveSettings(t.oOptions.current_view,true)})};this.AddView=function(){var e="view_"+Math.round(Math.random()*1e6);var i={};for(var s in this.oOptions.views[this.oOptions.current_view])i[s]=this.oOptions.views[this.oOptions.current_view][s];i.name=this.vars.mess.viewsNewView;this.ShowSettings(i,function(){var i=t.SaveSettings(e);t.oOptions.views[e]={name:i.name,columns:i.columns,sort_by:i.sort_by,sort_order:i.sort_order,page_size:i.page_size,saved_filter:i.saved_filter,custom_names:i.custom_names};t.bViewsChanged=true;var s=document["views_"+t.table_id];s.views_list.options[s.views_list.length]=new Option(i.name!=""?i.name:t.vars.mess.viewsNoName,e,true,true)})};this.EditView=function(e){this.ShowSettings(this.oOptions.views[e],function(){var i=t.SaveSettings(e);t.oOptions.views[e]={name:i.name,columns:i.columns,sort_by:i.sort_by,sort_order:i.sort_order,page_size:i.page_size,saved_filter:i.saved_filter,custom_names:i.custom_names};t.bViewsChanged=true;var s=document["views_"+t.table_id];s.views_list.options[s.views_list.selectedIndex].text=i.name!=""?i.name:t.vars.mess.viewsNoName})};this.DeleteView=function(e){if(!confirm(this.vars.mess.viewsDelete))return;var i=document["views_"+this.table_id];var s=i.views_list.selectedIndex;i.views_list.remove(s);i.views_list.selectedIndex=s<i.views_list.length?s:i.views_list.length-1;this.bViewsChanged=true;BX.ajax.get("/bitrix/components"+this.vars.component_path+"/settings.php?GRID_ID="+this.table_id+"&action=delview&view_id="+e+"&sessid="+t.vars.sessid)};this.ShowSettings=function(e,t){var i=false;if(!window["settingsDialog"+this.table_id]){window["settingsDialog"+this.table_id]=new BX.CDialog({content:'<form name="settings_'+this.table_id+'"></form>',title:this.vars.mess.settingsTitle,width:this.vars.settingWndSize.width,height:this.vars.settingWndSize.height,resize_id:"InterfaceGridSettingWnd"});i=true}window["settingsDialog"+this.table_id].ClearButtons();window["settingsDialog"+this.table_id].SetButtons([{title:this.vars.mess.settingsSave,action:function(){t();this.parentWindow.Close()}},BX.CDialog.prototype.btnCancel]);window["settingsDialog"+this.table_id].Show();var s=document["settings_"+this.table_id];if(i)s.appendChild(BX("view_settings_"+this.table_id));this.customNames=e.custom_names?e.custom_names:{};s.view_name.focus();s.view_name.value=e.name;var a=[];if(e.columns!=""){a=e.columns.split(",")}else{for(var n in this.oColsMeta)a[a.length]=n}var l={},r;for(n=0,r=a.length;n<r;n++)l[a[n]]=true;jsSelectUtils.deleteAllOptions(s.view_all_cols);for(n in this.oColsNames){if(!l[n]){var o=this.customNames[n]?this.customNames[n]:this.oColsNames[n];s.view_all_cols.options[s.view_all_cols.length]=new Option(o,n,false,false)}}jsSelectUtils.deleteAllOptions(s.view_cols);for(n in l){o=this.customNames[n]?this.customNames[n]:this.oColsNames[n];s.view_cols.options[s.view_cols.length]=new Option(o,n,false,false)}jsSelectUtils.selectOption(s.view_sort_by,e.sort_by);jsSelectUtils.selectOption(s.view_sort_order,e.sort_order);jsSelectUtils.selectOption(s.view_page_size,e.page_size);jsSelectUtils.deleteAllOptions(s.view_filters);s.view_filters.options[0]=new Option(this.vars.mess.viewsFilter,"");for(n in this.oOptions.filters)s.view_filters.options[s.view_filters.length]=new Option(this.oOptions.filters[n].name,n,n==e.saved_filter,n==e.saved_filter);if(s.set_default_settings){s.set_default_settings.checked=false;s.delete_users_settings.checked=false;s.delete_users_settings.disabled=true}s.up_btn.disabled=s.down_btn.disabled=s.rename_btn.disabled=s.add_btn.disabled=s.del_btn.disabled=true};this.RenameColumn=function(){var e=false;if(!window["renameDialog"+this.table_id]){window["renameDialog"+this.table_id]=new BX.CDialog({content:'<form name="rename_'+this.table_id+'"></form>',title:this.vars.mess.renameTitle,width:this.vars.renameWndSize.width,height:this.vars.renameWndSize.height,resize_id:"InterfaceGridRenameWnd",buttons:[{title:this.vars.mess.settingsSave,action:function(){var e=s.view_cols.value;var a=i.col_name.value;if(a.length>0){t.customNames[e]=a}else{a=t.oColsNames[e];delete t.customNames[e]}s.view_cols.options[s.view_cols.selectedIndex].text=a;this.parentWindow.Close()}},BX.CDialog.prototype.btnCancel]});e=true}window["renameDialog"+this.table_id].Show();var i=document["rename_"+this.table_id];var s=document["settings_"+this.table_id];if(e)i.appendChild(BX("rename_column_"+this.table_id));var a=s.view_cols.value;i.col_name.focus();i.col_name_def.value=this.oColsNames[a];i.col_name.value=this.customNames[a]?this.customNames[a]:this.oColsNames[a]};this.SaveSettings=function(e,i){var s=document["settings_"+this.table_id];var a="";var n=s.view_cols.length;for(var l=0;l<n;l++)a+=(a!=""?",":"")+s.view_cols[l].value;var r={GRID_ID:this.table_id,view_id:e,action:"savesettings",sessid:this.vars.sessid,name:s.view_name.value,columns:a,sort_by:s.view_sort_by.value,sort_order:s.view_sort_order.value,page_size:s.view_page_size.value,saved_filter:s.view_filters.value,custom_names:this.customNames};if(s.set_default_settings){r.set_default_settings=s.set_default_settings.checked?"Y":"N";r.delete_users_settings=s.delete_users_settings.checked?"Y":"N"}var o=null;if(i===true){o=function(){if(r.saved_filter&&t.oOptions.filters[r.saved_filter]){t.ApplyFilter(r.saved_filter)}else{t.Reload()}}}BX.ajax.post("/bitrix/components"+t.vars.component_path+"/settings.php",r,o);return r};this.ReloadViews=function(){if(t.bViewsChanged)t.Reload()};this.ShowViews=function(){this.bViewsChanged=false;var e=false;if(!window["viewsDialog"+this.table_id]){var i=new BX.CWindowButton({title:this.vars.mess.viewsApply,hint:this.vars.mess.viewsApplyTitle,action:function(){var e=document["views_"+t.table_id];if(e.views_list.selectedIndex!=-1)t.SetView(e.views_list.value);window["bxGrid_"+t.table_id].bViewsChanged=false;this.parentWindow.Close()}});window["viewsDialog"+this.table_id]=new BX.CDialog({content:'<form name="views_'+this.table_id+'"></form>',title:this.vars.mess.viewsTitle,buttons:[i,BX.CDialog.prototype.btnClose],width:this.vars.viewsWndSize.width,height:this.vars.viewsWndSize.height,resize_id:"InterfaceGridViewsWnd"});BX.addCustomEvent(window["viewsDialog"+this.table_id],"onWindowUnRegister",this.ReloadViews);e=true}window["viewsDialog"+this.table_id].Show();var s=document["views_"+this.table_id];if(e)s.appendChild(BX("views_list_"+this.table_id))};this.DragStart=function(){var e=document.body.appendChild(document.createElement("DIV"));e.style.position="absolute";e.style.zIndex=10;e.className="bx-drag-object";e.innerHTML=this.innerHTML;e.style.width=this.clientWidth+"px";this.__dragCopyDiv=e;this.className+=" bx-drag-source";var t=document.body.appendChild(document.createElement("DIV"));t.style.position="absolute";t.style.zIndex=20;t.className="bx-drag-arrow";this.__dragArrowDiv=t;return true};this.Drag=function(e,t){var i=this.__dragCopyDiv;i.style.left=e+"px";i.style.top=t+"px";return true};this.DragStop=function(){this.className=this.className.replace(/\s*bx-grid-drag-source/gi,"");this.__dragCopyDiv.parentNode.removeChild(this.__dragCopyDiv);this.__dragCopyDiv=null;this.__dragArrowDiv.parentNode.removeChild(this.__dragArrowDiv);this.__dragArrowDiv=null;return true};this.DragHover=function(e,i,s){t.HighlightGutter(this,true);this.className+=" bx-drag-over";var a=e.__dragArrowDiv;var n=jsUtils.GetRealPos(this);if(this.cellIndex<=e.cellIndex)a.style.left=n["left"]-6+"px";else a.style.left=n["right"]-6+"px";a.style.top=n["top"]-12+"px";return true};this.DragOut=function(e,i,s){t.HighlightGutter(this,false);this.className=this.className.replace(/\s*bx-drag-over/gi,"");var a=e.__dragArrowDiv;a.style.left="-1000px";return true};this.DragFinish=function(e,i,s,a){t.HighlightGutter(this,false);this.className=this.className.replace(/\s*bx-drag-over/gi,"");if(this==e)return true;var n=BX(t.table_id);var l=0;for(var r=0;r<2;r++){var o=n.rows[1].cells[r];if(o.className&&(o.className.indexOf("bx-actions-col")!=-1||o.className.indexOf("bx-checkbox-col")!=-1))l++}var c=[];for(var d in t.oColsMeta)c[c.length]=d;var h=e.cellIndex-l;var f=this.cellIndex-l;var v=c[h];if(f<h){for(r=h;r>f;r--)c[r]=c[r-1]}else{for(r=h;r<f;r++)c[r]=c[r+1]}c[f]=v;var u="";for(r=0;r<c.length;r++)u+=(u!=""?",":"")+c[r];t.SaveColumns(u);return true};this.InitFilter=function(){var e=BX("flt_header_"+this.table_id);if(e)jsUtils.addEvent(e,"contextmenu",this.OnRowContext)};this.SwitchFilterRow=function(e,t){if(t){var i=this.menu.GetMenuByItemId(t.id);i.SetItemIcon(t,this.oFilterRows[e]?"":"checked")}else{var s=this.filterMenu[0].MENU;for(var a=0;a<s.length;a++){if(s[a].ID=="flt_"+this.table_id+"_"+e){s[a].ICONCLASS=this.oFilterRows[e]?"":"checked";break}}}var n=BX("flt_row_"+this.table_id+"_"+e);n.style.display=this.oFilterRows[e]?"none":"";this.oFilterRows[e]=this.oFilterRows[e]?false:true;var l=BX("a_minmax_"+this.table_id);if(l&&l.className.indexOf("bx-filter-max")!=-1)this.SwitchFilter(l);this.SaveFilterRows()};this.SwitchFilterRows=function(e){this.menu.PopupHide();var t=0;for(var i in this.oFilterRows){t++;if(t==1&&e==false)continue;this.oFilterRows[i]=e;var s=BX("flt_row_"+this.table_id+"_"+i);s.style.display=e?"":"none"}var a=this.filterMenu[0].MENU;for(t=0;t<a.length;t++){if(t==0&&e==false)continue;if(a[t].SEPARATOR==true)break;a[t].ICONCLASS=e?"checked":""}var n=BX("a_minmax_"+this.table_id);if(n&&n.className.indexOf("bx-filter-max")!=-1)this.SwitchFilter(n);this.SaveFilterRows()};this.SaveFilterRows=function(){var e="";for(var t in this.oFilterRows)if(this.oFilterRows[t])e+=(e!=""?",":"")+t;BX.ajax.get("/bitrix/components"+this.vars.component_path+"/settings.php?GRID_ID="+this.table_id+"&action=filterrows&rows="+e+"&sessid="+this.vars.sessid)};this.SwitchFilter=function(e){var t=e.className.indexOf("bx-filter-min")!=-1;e.className=t?"bx-filter-btn bx-filter-max":"bx-filter-btn bx-filter-min";e.title=t?this.vars.mess.filterShow:this.vars.mess.filterHide;var i=BX("flt_content_"+this.table_id);i.style.display=t?"none":"";BX.ajax.get("/bitrix/components"+this.vars.component_path+"/settings.php?GRID_ID="+this.table_id+"&action=filterswitch&show="+(t?"N":"Y")+"&sessid="+this.vars.sessid)};this.ClearFilter=function(e){for(var t=0,i=e.elements.length;t<i;t++){var s=e.elements[t];switch(s.type.toLowerCase()){case"text":case"textarea":s.value="";break;case"select-one":s.selectedIndex=0;break;case"select-multiple":for(var a=0,n=s.options.length;a<n;a++)s.options[a].selected=false;break;case"checkbox":s.checked=false;break;default:break}if(s.onchange)s.onchange()}BX.onCustomEvent(e,"onGridClearFilter",[]);e.clear_filter.value="Y";BX.submit(e)};this.ShowFilters=function(){var e=false;if(!window["filtersDialog"+this.table_id]){var i=new BX.CWindowButton({title:this.vars.mess.filtersApply,hint:this.vars.mess.filtersApplyTitle,action:function(){var e=document["filters_"+t.table_id];if(e.filters_list.value)t.ApplyFilter(e.filters_list.value);this.parentWindow.Close()}});window["filtersDialog"+this.table_id]=new BX.CDialog({content:'<form name="filters_'+this.table_id+'"></form>',title:this.vars.mess.filtersTitle,buttons:[i,BX.CDialog.prototype.btnClose],width:this.vars.filtersWndSize.width,height:this.vars.filtersWndSize.height,resize_id:"InterfaceGridFiltersWnd"});e=true}window["filtersDialog"+this.table_id].Show();var s=document["filters_"+this.table_id];if(e)s.appendChild(BX("filters_list_"+this.table_id))};this.AddFilter=function(e){if(!e)e={};var i="filter_"+Math.round(Math.random()*1e6);var s={name:this.vars.mess.filtersNew,fields:e};this.ShowFilterSettings(s,function(){var e=t.SaveFilter(i);t.oOptions.filters[i]={name:e.name,fields:e.fields};var s=document["filters_"+t.table_id];s.filters_list.options[s.filters_list.length]=new Option(e.name!=""?e.name:t.vars.mess.viewsNoName,i,true,true);if(t.filterMenu.length==4)t.filterMenu=BX.util.insertIntoArray(t.filterMenu,1,{SEPARATOR:true});var a={ID:"mnu_"+t.table_id+"_"+i,TEXT:BX.util.htmlspecialchars(e.name),TITLE:t.vars.mess.ApplyTitle,ONCLICK:"bxGrid_"+t.table_id+".ApplyFilter('"+i+"')"};t.filterMenu=BX.util.insertIntoArray(t.filterMenu,2,a)})};this.AddFilterAs=function(){var e=document.forms["filter_"+this.table_id];var t=this.GetFilterFields(e);this.ShowFilters();this.AddFilter(t)};this.EditFilter=function(e){this.ShowFilterSettings(this.oOptions.filters[e],function(){var i=t.SaveFilter(e);t.oOptions.filters[e]={name:i.name,fields:i.fields};var s=document["filters_"+t.table_id];s.filters_list.options[s.filters_list.selectedIndex].text=i.name!=""?i.name:t.vars.mess.viewsNoName;for(var a=0,n=t.filterMenu.length;a<n;a++){if(t.filterMenu[a].ID&&t.filterMenu[a].ID=="mnu_"+t.table_id+"_"+e){t.filterMenu[a].TEXT=BX.util.htmlspecialchars(i.name);break}}})};this.DeleteFilter=function(e){if(!confirm(this.vars.mess.filtersDelete))return;var i=document["filters_"+this.table_id];var s=i.filters_list.selectedIndex;i.filters_list.remove(s);i.filters_list.selectedIndex=s<i.filters_list.length?s:i.filters_list.length-1;for(var a=0,n=this.filterMenu.length;a<n;a++){if(t.filterMenu[a].ID&&t.filterMenu[a].ID=="mnu_"+t.table_id+"_"+e){this.filterMenu=BX.util.deleteFromArray(this.filterMenu,a);if(this.filterMenu.length==5)this.filterMenu=BX.util.deleteFromArray(this.filterMenu,1);break}}delete this.oOptions.filters[e];BX.ajax.get("/bitrix/components"+this.vars.component_path+"/settings.php?GRID_ID="+this.table_id+"&action=delfilter&filter_id="+e+"&sessid="+t.vars.sessid)};this.ShowFilterSettings=function(e,t){var i=false;if(!window["filterSettingsDialog"+this.table_id]){window["filterSettingsDialog"+this.table_id]=new BX.CDialog({content:'<form name="flt_settings_'+this.table_id+'"></form>',title:this.vars.mess.filterSettingsTitle,width:this.vars.filterSettingWndSize.width,height:this.vars.filterSettingWndSize.height,resize_id:"InterfaceGridFilterSettingWnd"});i=true}window["filterSettingsDialog"+this.table_id].ClearButtons();window["filterSettingsDialog"+this.table_id].SetButtons([{title:this.vars.mess.settingsSave,action:function(){t();this.parentWindow.Close()}},BX.CDialog.prototype.btnCancel]);window["filterSettingsDialog"+this.table_id].Show();var s=document["flt_settings_"+this.table_id];if(i)s.appendChild(BX("filter_settings_"+this.table_id));s.filter_name.focus();s.filter_name.value=e.name;this.SetFilterFields(s,e.fields)};this.SetFilterFields=function(e,t){for(var i=0,s=e.elements.length;i<s;i++){var a=e.elements[i];if(a.name=="filter_name")continue;var n=t[a.name]||"";switch(a.type.toLowerCase()){case"select-one":case"text":case"textarea":a.value=n;break;case"radio":case"checkbox":a.checked=a.value==n;break;case"select-multiple":var l=a.name.substr(0,a.name.length-2);var r=false;for(var o=0,c=a.options.length;o<c;o++){var d=t[l]?t[l]["sel"+a.options[o].value]:null;a.options[o].selected=a.options[o].value==d;if(a.options[o].value==d)r=true}if(!r&&a.options.length>0&&a.options[0].value=="")a.options[0].selected=true;break;default:break}if(a.onchange)a.onchange()}};this.GetFilterFields=function(e){var t={};for(var i=0,s=e.elements.length;i<s;i++){var a=e.elements[i];if(a.name=="filter_name")continue;switch(a.type.toLowerCase()){case"select-one":case"text":case"textarea":t[a.name]=a.value;break;case"radio":case"checkbox":if(a.checked)t[a.name]=a.value;break;case"select-multiple":var n=a.name.substr(0,a.name.length-2);t[n]={};for(var l=0,r=a.options.length;l<r;l++)if(a.options[l].selected)t[n]["sel"+a.options[l].value]=a.options[l].value;break;default:break}}return t};this.SaveFilter=function(e){var i=document["flt_settings_"+this.table_id];var s={GRID_ID:this.table_id,filter_id:e,action:"savefilter",sessid:this.vars.sessid,name:i.filter_name.value,fields:this.GetFilterFields(i)};BX.ajax.post("/bitrix/components"+t.vars.component_path+"/settings.php",s);return s};this.ApplyFilter=function(e){var t=document.forms["filter_"+this.table_id];this.SetFilterFields(t,this.oOptions.filters[e].fields);BX.submit(t)};this.OnDateChange=function(e){var t=false,i=false,s=false,a=false,n=false;if(e.value=="interval")n=t=i=s=true;else if(e.value=="before")i=true;else if(e.value=="after"||e.value=="exact")t=true;else if(e.value=="days")a=true;BX.findNextSibling(e,{tag:"span",class:"bx-filter-from"}).style.display=t?"":"none";BX.findNextSibling(e,{tag:"span",class:"bx-filter-to"}).style.display=i?"":"none";BX.findNextSibling(e,{tag:"span",class:"bx-filter-hellip"}).style.display=s?"":"none";BX.findNextSibling(e,{tag:"span",class:"bx-filter-days"}).style.display=a?"":"none";var l=BX.findNextSibling(e,{tag:"span",class:"bx-filter-br"});if(l)l.style.display=n?"":"none"}}
//# sourceMappingURL=script.map.js